#ifndef CUBE_INSTANCE_H
#define CUBE_INSTANCE_H

#include <list>
#include <vector>

//forward declaration
class CubeWorld;

typedef struct CubeInstanceData_s
{
   float mTransfMatrix[16];
   float mColor[4];
   float mEnable;
}CubeInstanceData;

class CubeInstance
{
public:
   CubeInstance(unsigned int id);
   CubeInstance(unsigned int id, const float trans_mat[16], const float color[4]);
   ~CubeInstance(void);

   void SetData(const float trans_mat[16], const float color[4]);
   void ResetData(void);
   
   void Enable(void){_mData.mEnable = true;}
   void Disable(void){_mData.mEnable =false;}
   bool IsEnabled(void){return _mData.mEnable;}

   void SetDataMatrix(float trans_mat[16]);
   void SetDataColor(float color[4]);
   void SetDataColor(float r, float g, float b, float a);
   void SetID(unsigned int id){  _mID = id; }

   void GetData(unsigned int id, float trans_mat[16], const float color[4]);
   const CubeInstanceData* GetData(void){return &_mData;}
   void GetDataMatrix(unsigned int id, float trans_mat[16]);
   void GetDataColor(float color[4]);
   unsigned int GetID(void){ return _mID; }
   
private:
   unsigned int _mID;
   CubeInstanceData _mData;
};

//singleton pattern

class CubeInstanceManager
{
public:
   static CubeInstanceManager* GetSingleton(void);

   CubeInstance* GetCubeInstance(unsigned int id);

   unsigned int GetCubeInstNums(void);

   CubeInstanceData* GetCubeInstPointer(void);
   unsigned int GetCubeInstTotalByteSize(void);

   bool PullCubeInstFrom(CubeWorld* world);

   bool PushCubeInstTo(const char* buf_name);

   bool PushCubeInstTo(unsigned int buf_id);

   
private:
   CubeInstanceManager(void);
   ~CubeInstanceManager(void);

   CubeInstance* _CreateCubeInst(unsigned int id, const float trans_mat[16], const float color[4]);
   
   
private:
   std::vector<CubeInstance*> _mCubeInstVector;  //FIXME: pointer as element is not correct!
   std::vector<CubeInstanceData> _mCubeInstBuffer;
   CubeInstanceData* _mCubeInstBufferPointer;
   bool _mCubeInstBufferDirty;
   static CubeInstanceManager* _mSingleton;
};


#endif //CUBE_INSTANCE_H
